<?php namespace Core\Myapp\Router;

class Rewrite
{
    protected $_moduleName;
    protected $_controllerName;
    protected $_actionName;
    protected $_params;

    public function match(\Core\Zend\Controller\Request\Request $request)
    {
        $path = trim($request->getPathInfo(), '/');
        if(!$path) {
            return false;
        }
        $segments = explode('/', $path);
        if(empty($segments[0]) || $segments[0]!='admin') //maybe we need add an option to help user select admin front name
            return false;
        else {
            $this->_moduleName = isset($segments[1]) ? $segments[1] : 'default_module';
            $this->_controllerName = isset($segments[2]) ? $segments[2] : 'index';
            $this->_actionName = isset($segments[3]) ? $segments[3] : 'index';
            // set parameters from pathinfo
            for ($i = 4, $l = sizeof($segments); $i < $l; $i += 2) {
                $request->setParam($segments[$i], isset($segments[$i+1]) ? urldecode($segments[$i+1]) : '');
            }
            return true;
        }
    }
}